<?php
/*
 * 均源WAP & 隐藏路径下载服务器 & 雨中漫步
 */
define('IN_APP', str_replace('\\', '/', dirname(dirname(__FILE__))). '/');
define('DEBUG', 0);

DEBUG && function_exists('ini_set') && ini_set('display_errors', 'On');

require_once IN_APP. 'jy_conf/config.php';
require_once IN_APP. 'jy_core/the_core.php';

$f = (isset($_GET['f']) && !empty($_GET['f']) ) ? $_GET['f'] : '';
if(empty($f)) exit('invalid path');

$f = base64_decode($f);
if(empty($f)) exit('invalid path');

$token = md5(date('YmdH').CONFIG_CS_KEY);
$l = explode('|', $f);
$n = count($l)>1 ? str_replace($l[0].'|', '', $f): '' ;
$f = $l[0];
$f = encrypt::de($f, $token);

$file = IN_APP . $f;
if (is_file($file)) {
	$file_exts = explode('.', $file);
	$file_exts = is_array($file_exts) ? end($file_exts) : false;
	if($file_exts && in_array($file_exts, array('gif', 'bmp', 'jpg', 'jpeg', 'png'))){
		header('Location: ../'.$f);
		die;
	}
	
	$name = $n == '' ? basename($file) :encrypt::de($n, $token);
	ob_start();
	header('Content-Description: File Transfer');
	$ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT']: '';
	if(preg_match("/MSIE/", $ua)) {
		$name = str_replace("+", "%20", urlencode($name));
		header('Content-Disposition: attachment; filename="'.$name .'"');
	}elseif(preg_match("/Firefox/", $ua)) {
		header('Content-Disposition: attachment; filename*="utf8\'\''.$name.'"');
	}else{
		header('Content-Disposition: attachment; filename="'.$name.'"');
	}
	header('Content-Type: application/octet-stream; name=' . $name);
	header('Content-Transfer-Encoding: binary');
	header('Expires: 0');
	header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
	header('Pragma: public');
	header('Content-Length: ' . filesize($file));
	
	ob_clean();
	//flush();
	readfile($file);
	exit;
}else{
	exit('invalid path');
}


?>